<template>
  <div>
    <el-descriptions :column="2" size="default" border v-for="(item,index) in obj.orderDet"
      :key="item.id">
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            订单编号
          </div>
        </template>
        {{item.orderNumber}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            资金分配
          </div>
        </template>
        （仓库实收合计 = 物流费用 +
        商品金额 -
        合伙人收益 - 平台服务费 - 配送费）
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            订单状态
          </div>
        </template>
        {{item.status}}
      </el-descriptions-item>

      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            配送专员
          </div>
        </template>
        {{item.sendName}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            补货状态
          </div>
        </template>
        {{item.buhuo}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            商品金额
          </div>
        </template>
        {{obj.ordersumMoney}}元
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            入库状态
          </div>
        </template>
        {{item.ruk}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            物流费用
          </div>
        </template>
        {{item.deliveryMoney !=0?item.deliveryMoney+'元':'——'}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            收 货 人
          </div>
        </template>
        {{item.name}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            配 送 费
          </div>
        </template>
        {{item.sendMoney !=0?item.sendMoney+'元':'——'}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            联系电话
          </div>
        </template>
        {{item.phone}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            合伙人收益
          </div>
        </template>
        {{item.redPacketMoney}}元
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            下单时间
          </div>
        </template>
        {{parseTime(item.creationTime)}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            平台服务费
          </div>
        </template>
        {{item.platformMoney}}元
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            出库时间
          </div>
        </template>
        {{item.status5Time !=null && item.buhuo !='待补货' && item.buhuo !='已补货'?parseTime(item.status5Time):'——'}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            仓库实收合计
          </div>
        </template>
        {{calculate.subtract(calculate.subtract(calculate.subtract( calculate.add(item.deliveryMoney,obj.ordersumMoney),item.redPacketMoney),item.platformMoney),item.sendMoney)}}元
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            签收时间
          </div>
        </template>
        {{item.status6Time !=null?parseTime(item.status6Time):'——'}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            订单备注
          </div>
        </template>
        {{item.remark}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            补货时间
          </div>
        </template>
        {{item.buhuo =='已补货'?parseTime(item.status5Time):'——'}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            申请取消
          </div>
        </template>
        <el-button type='primary' text v-if="item.wxOrderCancellation !=null"
          @click="dialogTableVisible(index)">点击查看</el-button>
        <span v-else>——</span>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            入库时间
          </div>
        </template>
        {{item.status8Time !=null && item.buhuo =='已入库'?parseTime(item.status8Time):"——"}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <div class="cell-item">
            收货地址
          </div>
        </template>
        {{item.address}}
      </el-descriptions-item>
    </el-descriptions>
    <div v-for="item in obj.orderDetails" :key="item.id">
      <el-descriptions direction="vertical" :column="11" size="default" border>
        <template #title>
          <el-button type="primary" text>商品信息</el-button>
        </template>
        <el-descriptions-item label="商品图片">
          <el-image style="width: 100px; height: 100px" :src='item.image' fit="scale-down">
          </el-image>
        </el-descriptions-item>
        <el-descriptions-item label="活动标题">{{item.titleName}}</el-descriptions-item>
        <el-descriptions-item label="活动名称">
          <span v-if="item.titleName==item.acProductName">基础商品</span>
          <span v-else>{{item.acProductName}}</span>
        </el-descriptions-item>
        <el-descriptions-item label="商品规格">{{item.spec}}</el-descriptions-item>
        <el-descriptions-item label="套餐数量">{{item.packageNum}}</el-descriptions-item>
        <el-descriptions-item label="商品单价">{{item.orderPrice}}元</el-descriptions-item>
        <el-descriptions-item label="下单数量">{{item.orderNum}}</el-descriptions-item>
        <el-descriptions-item label="货物小计">{{item.productNum}} {{item.productUnit}}
        </el-descriptions-item>
        <el-descriptions-item label="商品金额">{{obj.ordersumMoney}}元
        </el-descriptions-item>
        <el-descriptions-item label="物流费用" v-if="obj.deliveryMoney !=0">{{obj.deliveryMoney}}元
        </el-descriptions-item>
        <el-descriptions-item label="物流费用" v-else>——</el-descriptions-item>
        <el-descriptions-item label="订单合计">
          {{calculate.add(calculate.multiply(item.orderPrice,item.orderNum),obj.deliveryMoney)}}
        </el-descriptions-item>
      </el-descriptions>
      <el-descriptions :column="1" border>
        <el-descriptions-item label="发货仓库">
          {{obj.cangku}}</el-descriptions-item>
        <el-descriptions-item label="酒票">
          <div v-for="(items,index) in item.giftBoxUtil" :key="index">
            <div>{{items.wineName}} {{items.wineMoney}}
              {{items.wineUnit}}*{{items.wineNum}}张
              &nbsp;&nbsp;&nbsp;&nbsp;
              合计：{{calculate.multiply(items.wineMoney,items.wineNum)}}{{items.wineUnit}}
            </div>
            <el-divider v-if="item.giftBoxUtil.length !=index+1 ">
            </el-divider>
          </div>
        </el-descriptions-item>
        <el-descriptions-item label="礼盒" v-if="obj.arst==0">
          {{item.giftCount}}个
        </el-descriptions-item>

        <el-descriptions-item v-if="obj.arst==1" label="礼盒">
          <div v-for="(items,indexK) in item.giftBoxUtil2" :key="indexK">
            <div>{{items.wineName}} {{items.wineMoney}}
              {{items.wineUnit}}*{{items.wineNum}}张
              &nbsp;&nbsp;&nbsp;&nbsp;
              合计：{{calculate.multiply(items.wineMoney,items.wineNum)}}{{items.wineUnit}}
            </div>
            <el-divider v-if="item.giftBoxUtil2.length !=indexK+1 ">
            </el-divider>
          </div>
        </el-descriptions-item>
      </el-descriptions>
    </div>
    <el-drawer v-model="innerDrawer" direction="ltr" title="申请取消" :append-to-body="true"
      :before-close="handleClose">
      <div>
        <el-steps finish-status="success" direction="vertical" :active="activeturndown">
          <el-step :title="parseTime(item.creationTime)" v-for="(item,index) in  orderDetdown"
            :key="index">
            <template #title>
              <p>{{item.cancellationStatus==0?'取消时间：':"驳回时间："}} {{parseTime(item.creationTime) }}
              </p>
            </template>
            <template #description>
              <p v-if="item.cancellationStatus==0">{{item.cancellationStatus==0?'申请原因：':'驳回原因：'}}
                {{item.cause}}</p>
            </template>
          </el-step>
          <el-step v-if="obj.status7Time !=''&&  obj.status7Time !=null ">
            <template #title>
              <p class="redTime"> 取消时间：{{parseTime(obj.status7Time) }}</p>
            </template>
            <template #description>
              <p class="redTime"> 同意原因：商家已同意</p>
            </template>
          </el-step>
        </el-steps>
      </div>
    </el-drawer>
  </div>
</template>
 
<script setup>
import {
  reactive,
  getCurrentInstance,
  onMounted,
  inject,
  computed,
  ref,
} from "vue";
import { calculate } from "@/utils/mathjs";
const ObjDetailsSon = inject("ObjDetailsSon");
const obj = ref({});
const innerDrawer = ref(false);

watch(
  () => ObjDetailsSon.value,
  (newValue) => {
    obj.value = ObjDetailsSon.value;
    // console.log(obj.value, ";;;;;;;;;;");
  },
  { deep: true }
);
onMounted(async () => {
  await nextTick();
  obj.value = ObjDetailsSon.value;
});
function handleClose() {
  innerDrawer.value = false;
}
const activeturndown = ref(1);
const orderDetdown = ref([]);
function dialogTableVisible(e) {
  console.log(e, ";;;;;;");
  if (obj.value.orderDet[e].wxOrderCancellation != null) {
    if (obj.value.status7Time != null && obj.value.status7Time != "") {
      activeturndown.value =
        obj.value.orderDet[e].wxOrderCancellation.length + 1;
    } else {
      activeturndown.value = obj.value.orderDet[e].wxOrderCancellation.length;
    }
    orderDetdown.value = obj.value.orderDet[e].wxOrderCancellation;
  }
  innerDrawer.value = true;
}
</script>
<style scoped lang="scss">
.redTime {
  color: red;
}
</style>